import { ElasticsearchClientProp } from "./types";
import { ElasticsearchClientV6 } from "./builder/v6";
import { ElasticsearchClientV7 } from "./builder/v7";
import { ElasticsearchClient } from "./client";

export function createElasticsearchClient(props: ElasticsearchClientProp): ElasticsearchClient {
  const { version } = props;
  if (/^7\.\d+\.\d+/.test(version)) {
    // V7
    return new ElasticsearchClientV7(props);
  } else if (/^6\.\d+\.\d+/.test(version)) {
    // V6
    return new ElasticsearchClientV6(props);
  }

  // 默认返回v7版本
  return new ElasticsearchClientV7(props);
}
